﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using Windows.Storage;
using System.IO.IsolatedStorage;
using System.Xml.Serialization;

namespace TestMatrix.Model
{
    public class ConstantDefinition
    {
        //TestMatrix.sqlite
        public static string DB_FILE_NAME = "TestMatrix.sqlite";

        //DateSetting.xml
        public static string DATE_SETTING_FILEN_AME = "DateSetting.xml";

        //DataRefreshSetting.xml
        public static string DATA_REFRESH_SETTING_FILEN_AME = "DataRefreshSetting.xml";

        public static string LAST_REFRESHED_DATE = "LastRefreshedDate";

        public static string USER_ALIAS = "Alias";

        public static string USER_PASSWORD = "Password";

        //The Database path 
        public static string DB_PATH = Path.Combine(Path.Combine(ApplicationData.Current.LocalFolder.Path, ConstantDefinition.DB_FILE_NAME));      

        //All
        //Last 30 Days,
        //Last 6 Months,
        //Last 12 Months,
        public static string DATE_FILTER_TYPE = "Last 30 Days";

        public static string GetDBPath()
        {
            string db_Path = "";
            try
            {
                using (IsolatedStorageFile myIsolatedStorage = IsolatedStorageFile.GetUserStoreForApplication())
                {
                    using (IsolatedStorageFileStream stream = myIsolatedStorage.OpenFile(ConstantDefinition.DATA_REFRESH_SETTING_FILEN_AME, FileMode.Open))
                    {
                        XmlSerializer serializer = new XmlSerializer(typeof(List<PhoneSetting>));
                        List<PhoneSetting> data = (List<PhoneSetting>)serializer.Deserialize(stream);

                        foreach (var t in data)
                        {
                            db_Path = Path.Combine(Path.Combine(ApplicationData.Current.LocalFolder.Path, t.DBFileName.ToString())); ;
                        }
                    }
                }
            }
            catch
            {
                //db_Path = Path.Combine(Path.Combine(ApplicationData.Current.LocalFolder.Path, ConstantDefinition.DB_FILE_NAME));
                return null;
            }
            return db_Path;
        }

    }
}
